{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 一些常见的比较经典的小问题，累加更新"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 判断一句话是否完全由词典中的词构成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "dic = set([\"NLP\", \"是\", \"人工智能\", \"的\", \"一个\", \"重要\", \"方向\"])\n",
    "def word_break(str):\n",
    "    \n",
    "    could_break = [False] * (len(str) + 1)\n",
    "    could_break[0] = True\n",
    "\n",
    "    for i in range(1, len(could_break)):\n",
    "        for j in range(0, i):\n",
    "            if str[j:i] in dic and could_break[j] == True:\n",
    "                could_break[i] = True\n",
    "\n",
    "    return could_break[len(str)] == True\n",
    "\n",
    "print(word_break(\"NLP是人工智能的一个重要方向\"))\n",
    "print(word_break(\"人工智能的重要方向是NLP\"))\n",
    "print(word_break(\"CV也是人工智能的一个方向\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
